#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
const ll N = 2e5 + 10;

ll pre[N];
bool was[N];
ll n, col[N];
vector<pair<ll, ll>> reb[N];
ll zn[N];
map<ll, ll> cnt[N];
ll q;
ll costt = 0;
void dfs(ll u)
{
    was[u] = 1;
    for (auto v : reb[u])
    {
        if (was[v.first])
        {
            pre[u] = v.first;
            continue;
        }

        if (col[v.first] == col[u])
        {
            costt += 0;
        }
        else
        {
            costt += v.second;
        }

        dfs(v.first);

        zn[v.first] = v.second;
        cnt[u][col[v.first]] += zn[v.first];
    }
}
void update(ll v, ll x)
{
    ll old = col[v];

    if (v != 1)
    {
        cnt[pre[v]][old] -= zn[v];
        cnt[pre[v]][x] += zn[v];
        if (col[pre[v]] == old)
        {
            costt += zn[v];
        }

        if (col[pre[v]] == x)
        {
            costt -= zn[v];
        }
    }
    costt += cnt[v][old];
    costt -= cnt[v][x];
    col[v] = x;
} // 清理函数：重置所有数据结构
void clr()
{
    for (int i = 1; i <= n; i++)
    {
        reb[i].clear();
        was[i] = false;
        cnt[i].clear();
        zn[i] = 0;
    }
    costt = 0; // 重置总成本
}
void solve()
{
    cin >> n >> q;
    for (ll i = 1; i <= n; i++)
    {
        cin >> col[i];
    }
    for (ll i = 1; i < n; i++)
    {
        ll u, v, c;
        cin >> u >> v >> c;
        reb[u].push_back({v, c});
        reb[v].push_back({u, c});
    }

    dfs(1);

    // 处理查询
    while (q--)
    {
        int pos, x;
        cin >> pos >> x;
        update(pos, x);        // 更新顶点颜色
        cout << costt << "\n"; // 输出当前总成本
    }

    clr(); // 清理数据，准备下一个测试用例
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
